<?php defined('InNcPHP') or exit('Access Invalid!');?>
<link rel="stylesheet" type="text/css" href="<?php echo RESOURCE_URL;?>/common/jquery-ui/themes/ui-lightness/jquery.ui.css"  />
<link rel="stylesheet"  type="text/css" href="<?php echo RESOURCE_URL;?>/common/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.css">
<style>
    .show { display: block; }
    .hide { display: none; }

</style>

<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <h3><?php echo $lang['bargain_index_ticket'];?></h3>
            <?php echo $output['top_link'];?>
        </div>
    </div>
    <div class="fixed-empty"></div>
    <!-- 提交表单开始 -->
    <form id="bargain_form" method="post" enctype="multipart/form-data">
        <input type="hidden" name="form_submit" value="ok" />
        <input type="hidden" name="bargain_id" value="<?php echo $output['bargain_info']['bargain_id']?>">
        <table class="table tb-type2 nobdb">
            <tbody>
            <!-- 所属商家 -->
            <tr>
                <td colspan="2" class="required">
                    <label class="validation"><?php echo $lang['bargain_index_merchant'];?>: </label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform">
                    <select name="merchant_id">
                        <option value=""><?php echo $lang['nc_please_choose'];?>...</option>
                        <?php if (is_array($output['merchants'])): ?>
                            <?php foreach ($output['merchants'] as $k => $v): ?>
                                <option value="<?php echo $v['merchant_id']; ?>" <?php echo $output['bargain_info']['merchant_id'] == $v['merchant_id'] ? 'selected' : ''; ?>><?php echo $v['mc_shop_name']; ?></option>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </select>
                </td>
                <td class="vatop tips"></td>
            </tr>
            <!-- 是否属于爆款 -->
            <tr>
                <td colspan="2" class="required"><?php echo '是否属于爆款';?>: </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform onoff">
                    <label for="is_hot1" class="cb-enable <?php if($output['bargain_info']['is_hot']=='1'){ echo"selected"; }?>"><span><?php echo $lang['nc_yes'];?></span></label>
                    <label for="is_hot0" class="cb-disable <?php if($output['bargain_info']['is_hot']=='0'){ echo"selected"; }?>"><span><?php echo $lang['nc_no'];?></span></label>
                    <input id="is_hot1" name="is_hot" <?php if($output['bargain_info']['is_hot']=='1'){ echo"checked"; }?> value="1" type="radio">
                    <input id="is_hot0" name="is_hot" <?php if($output['bargain_info']['is_hot']=='0'){ echo"checked"; }?> value="0" type="radio">
                </td>
                <td class="vatop tips"></td>
            </tr>
            <!-- 商品类型 -->
            <tr>
                <td colspan="2" class="required">
                    <label class="validation">商品发货类型: </label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform">
                    <select name="type">
                        <option value="0" <?php echo $output['bargain_info']['type'] =='0'? 'selected':'';?>>物流发货</option>
                        <option value="1" <?php echo $output['bargain_info']['type'] =='1'? 'selected':'';?>>到店消费</option>
                    </select>
                </td>
                <td class="vatop tips"></td>
            </tr>
            <!-- 地址 -->
            <?php if($output['bargain_info']['type']==1) {?>
            <tr class="add_res" >
                <td colspan="2" class="required">
                    <label class="validation">商家所属于区域: </label>
                </td>
            </tr>
            <tr class="noborder add_res" >
                <td class="vatop rowform">
                    <select id="store_areaId_01" name="province_id" class="class-select">
                        <option value="">省份</option>
                        <?php if (is_array($output['provinces'])): ?>
                            <?php foreach ($output['provinces'] as $k => $v): ?>
                                <option value="<?php echo $v['area_id']; ?>" <?php echo $output['bargain_info']['firm_province_id'] == $v['area_id']?'selected':''; ?>><?php echo $v['name']; ?></option>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </select>
                    <select id="store_areaId_02" name="city_id" class="class-select">
                        <option value="">城市</option>
                        <?php if (is_array($output['citys'])): ?>
                            <?php foreach ($output['citys'] as $k => $v): ?>

                                <option value="<?php echo $v['area_id']; ?>" <?php echo $output['bargain_info']['firm_city_id'] == $v['area_id'] ? 'selected' : ''; ?>><?php echo $v['name']; ?></option>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </select>
                    <select id="store_areaId_03" name="area_id" class="class-select">
                        <option value="">区/县</option>
                        <?php if (is_array($output['areas'])): ?>
                            <?php foreach ($output['areas'] as $k => $v): ?>
                                <option value="<?php echo $v['area_id']; ?>" <?php echo $output['bargain_info']['firm_area_id'] == $v['area_id'] ? 'selected' : ''; ?>><?php echo $v['name']; ?></option>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </select>
                </td>
                <td class="vatop tips"></td>
            </tr>
            <?php  }?>
            <!-- 商品标题 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation"><?php echo $lang['bargain_index_title'];?>:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="title" class="txt" value="<?php echo $output['bargain_info']['bg_title'];?>"></td>
                <td class="vatop tips"><?php echo $lang['bargain_add_title_notice'];?></td>
            </tr>

            <!-- 商品价格 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation"><?php echo $lang['bargain_add_show_price'];?>:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="show_price" class="txt" value="<?php echo $output['bargain_info']['bg_price'];?>"></td>
                <td class="vatop tips"><?php echo $lang['bargain_add_show_price_notice'];?></td>
            </tr>
            <!-- 商品库存 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation"><?php echo $lang['bargain_add_store'];?>:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="store" class="txt" value="<?php echo $output['bargain_info']['bg_store'];?>"></td>
                <td class="vatop tips"><?php echo $lang['bargain_add_store_notice'];?></td>
            </tr>
            <!-- 砍价最低价 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation"><?php echo $lang['bargain_add_market_price'];?>:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="market_price" class="txt" value="<?php echo $output['bargain_info']['bg_floorprice'];?>" ></td>
                <td class="vatop tips"><?php echo $lang['bargain_add_market_notice'];?></td>
            </tr>
            <!-- 设置朋友代付金额 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="">朋友代付金额:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="friend_price" class="txt" value="<?php echo $output['bargain_info']['friends_sum']?>"></td>
                <td class="vatop tips">设置价格请用‘,’隔开，例如2.5,3,5 可保留两位小数！（若此项不设置，则为默认显示价格）</td>
            </tr>
            <!-- 设置朋友每日砍价次数上限 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="">朋友每日砍价次数上限:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="true_sum" class="txt"   value="<?php echo $output['bargain_info']['true_sum'] ?>"></td>
                <td class="vatop tips">设置朋友每日的砍价次数上限，如‘500’,所有属于该条活动的订单，每个朋友每天只能砍500次</td>
            </tr>

            <!-- 单次砍价最低价 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation"><?php echo '砍价成功的范围' ;?>:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="min_price" class="txt" value="<?php echo $output['bargain_info']['min_price'];?>" style="width: 100px;">
                    -----
                    <input type="text" name="max_price" class="txt" value="<?php echo $output['bargain_info']['max_price'];?>" style="width: 100px;">
                </td>
                <td class="vatop tips"><?php echo '设置砍价成功的优惠价格范围,如‘5-10’,若砍价成功价格就在5元至10元随机生成！';?></td>
            </tr>


            <!-- 第二次点击砍价概率 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation"><?php echo $lang['bargain_index_cishu'];?>:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="degree" class="txt" value="<?php echo $output['bargain_info']['bg_degree'];?>"></td>
                <td class="vatop tips"><?php echo $lang['bargain_add_show_cishu'];?></td>
            </tr>


            <!-- 参与活动的人数 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation">参与活动人数:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="bg_rs" class="txt" value="<?php echo $output['bargain_info']['bg_rs'] ?>"></td>
                <td class="vatop tips">请输入整数</td>
            </tr>

            <!-- 活动分享次数 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation">活动分享次数:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="share_sun" class="txt" value="<?php echo $output['bargain_info']['share_sun'] ?>"></td>
                <td class="vatop tips">请输入整数</td>
            </tr>


            <!-- 活动开始时间 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation"><?php echo $lang['bargain_index_start_time'] ;?>:</label>
                </td>
            </tr>
            <tr>
                <td class="rowform"><input type="text" name="search_stime" value="<?php echo date('Y-m-d H:i',$output['bargain_info']['start_time']); ?>"  id="search_stime" class="txt date" ></td>
            </tr>
            <!-- 活动结束时间 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation"><?php echo $lang['bargain_index_end_time'] ;?>:</label>
                </td>
            </tr>
            <tr>
                <td class="rowform"><input type="text" name="search_etime" value="<?php echo date('Y-m-d H:i',$output['bargain_info']['end_time']); ?>" id="search_etime" class="txt date"></td>
            </tr>
            <!-- 推荐 -->
            <tr>
                <td colspan="2" class="required"><?php echo $lang['bargain_add_recommend'];?>: </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform onoff">
                    <label for="recommend1" class="cb-enable <?php if($output['bargain_info']['if_show']=='1'){ echo"selected"; }?>"><span><?php echo $lang['nc_yes'];?></span></label>
                    <label for="recommend0" class="cb-disable <?php if($output['bargain_info']['if_show']=='0'){ echo"selected"; }?>"><span><?php echo $lang['nc_no'];?></span></label>
                    <input id="recommend1" name="if_show" <?php if($output['bargain_info']['if_show']=='1'){ echo"checked"; }?> value="1" type="radio" >
                    <input id="recommend0" name="if_show" <?php if($output['bargain_info']['if_show']=='0'){ echo"checked"; }?> value="0" type="radio">
                </td>
                <td class="vatop tips"></td>
            </tr>


            <!-- 是否需要关注公众号 -->
            <tr>
                <td colspan="2" class="required"><?php echo '是否需要关注公众号';?>: </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform onoff if_code">
                    <label for="if_code1" class="cb-enable code_0 <?php if($output['bargain_info']['if_code']=='1'){ echo"selected"; }?>"><span><?php echo $lang['nc_yes'];?></span></label>
                    <label for="if_code0" class="cb-disable code_1 <?php if($output['bargain_info']['if_code']=='0'){ echo"selected"; }?>"><span><?php echo $lang['nc_no'];?></span></label>
                    <input id="if_code1" name="if_code"  <?php if($output['bargain_info']['if_code']=='1'){ echo"checked"; }?>  value="1" type="radio">
                    <input id="if_code0" name="if_code" <?php if($output['bargain_info']['if_code']=='0'){ echo"checked"; }?> value="0" type="radio">
                    <input type="hidden" name="checkcode" value="">
                </td>
                <td class="vatop tips"></td>
            </tr>
            <!-- 二维码图片 -->
            <?php  if($output['bargain_info']['if_code']=='1'){ ?>
            <tr class="noborder code_img">
                <td colspan="2" class="required">
                    <label class="validation"><?php echo '二维码LOGO';?>:</label>
                </td>
            </tr>
            <tr class="noborder code_img">
                <td class="vatop rowform"><span class="type-file-show">
                      <span class="type-file-show">
                        <img class="show_image" src="<?php echo ADMIN_TEMPLATES_URL;?>/images/preview.png">
                        <div class="type-file-preview" style="display: none;">
                            <img id="view_img" src="<?php echo $output['bargain_info']['code_img']; ?>" style="max-height: 100px;max-width: 100px;">
                        </div>
                    </span>
                    </span> <span class="type-file-box">
                        <input type='text' name='textfield' id='textfield2' class='type-file-text' />
                        <input type='button' name='button' id='button' value='' class='type-file-button' />
                        <input name="code_img" type="file" class="type-file-file" id="image2" size="30" hidefocus="true" />
                    </span>
                </td>
                <td class="vatop tips"><?php echo $lang['bargain_add_image_notice'];?></td>
            </tr>
           <?php } ?>

            <!-- 封面图片 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation"><?php echo $lang['bargain_add_image'];?>:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><span class="type-file-show">
                        <span class="type-file-show">
                        <img class="show_image" src="<?php echo ADMIN_TEMPLATES_URL;?>/images/preview.png">
                        <div class="type-file-preview" style="display: none;">
                            <img id="view_img" src="<?php echo $output['bargain_info']['bg_thumb']; ?>" style="max-height: 100px;max-width: 100px;">
                        </div>
                    </span>
                    </span> <span class="type-file-box">
                        <input type='text' name='textfield' id='textfield' class='type-file-text' />
                        <input type='button' name='button' id='button' value='' class='type-file-button' />
                        <input name="thumb" type="file" class="type-file-file" id="image" size="30" hidefocus="true" />
                    </span>
                </td>
                <td class="vatop tips"><?php echo $lang['bargain_add_image_notice'];?></td>
            </tr>
            <!-- 详情页图片 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation"><?php echo $lang['bargain_add_face'];?>:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><span class="type-file-show">
                        <span class="type-file-show">
                        <img class="show_image" src="<?php echo ADMIN_TEMPLATES_URL;?>/images/preview.png">
                        <div class="type-file-preview" style="display: none;">
                            <img id="view_img" src="<?php echo $output['bargain_info']['bg_face']; ?>" style="max-height: 100px;max-width: 100px;">
                        </div>
                    </span>
                    </span> <span class="type-file-box">
                        <input type='text' name='textfield' id='textfield1' class='type-file-text' />
                        <input type='button' name='button' id='button' value='' class='type-file-button' />
                        <input name="face" type="file" class="type-file-file" id="image1" size="30" hidefocus="true" />
                    </span>
                </td>
                <td class="vatop tips"><?php echo $lang['bargain_add_face_notice'];?></td>
            </tr>
            <!-- 商品详情 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation"><?php echo $lang['bargain_add_detail'];?>:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td colspan="2" class="vatop rowform">
                    <textarea id="content" name="content" style="width:70%;height: 400px;"><?php echo $output['bargain_info']['bg_detail']; ?></textarea>
                </td>
            </tr>
            <!-- 公司信息 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation"><?php echo $lang['bargain_add_firm_info'];?>:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td colspan="2" class="vatop rowform">
                    <textarea id="content2" name="content2" style="width:70%;height: 300px;"><?php echo $output['bargain_info']['firm_info']; ?></textarea>
                </td>
            </tr>
            <!-- 活动规则 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation"><?php echo $lang['bargain_add_rule'];?>:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td colspan="2" class="vatop rowform">
                    <textarea id="content1" name="content1" style="width:70%;height: 300px;"><?php echo $output['bargain_info']['bg_rule']; ?></textarea>
                </td>
            </tr>
            <!-- 提交 -->
            <tr class="tfoot">
                <td colspan="2" >
                    <a href="JavaScript:void(0);" class="btn" id="submitBtn">
                        <span><?php echo $lang['nc_submit'];?></span>
                    </a>
                </td>
            </tr>
            </tfoot>
        </table>
    </form>
</div>

<script type="text/javascript" SRC="./resource/kindeditor/kindeditor-min.js"></script>
<script type="text/javascript" src="<?php echo RESOURCE_URL;?>/common/jquery-ui/jquery.ui.js"></script>
<script type="text/javascript" src="<?php echo RESOURCE_URL;?>/common/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.js"></script>
<script type="text/javascript" src="<?php echo RESOURCE_URL;?>/common/jquery-ui/i18n/zh-CN.js" charset="utf-8"></script>

<script>
    //开始日期
    /*   $('#search_stime').datepicker({
     dateFormat: 'yy-mm-dd',
     onClose: function(selectedDate) {
     $("#search_etime").datepicker("option", "minDate", selectedDate);
     }
     });
     //结束日期
     $('#search_etime').datepicker({
     dateFormat: 'yy-mm-dd',
     onClose: function(selectedDate) {
     $("#search_stime").datepicker("option", "maxDate", selectedDate);
     }
     });*/


    $('#search_stime').datetimepicker({
        controlType: 'select'
    });

    $('#search_etime').datetimepicker({
        controlType: 'select'
    });
    $('.if_code label').click(function(){
        if($(".code_1").is('.selected')){
            $('.code_img').show();
            $('[name ="checkcode"]').val(1);
        }else{
            $('.code_img').hide();
            $('[name ="checkcode"]').val(0);
        }
    })

    //实例化富文本编辑器
    KindEditor.ready(function(K){
        K.create('textarea[name="content"]', {
            themeType: 'simple',
            resizeType: 1,
            uploadJson: './resource/kindeditor/php/upload_json.php',
            fileManagerJson: './resource/kindeditor/php/file_manager_json.php',
            allowFileManager: true,
            afterBlur: function(){this.sync();}
        });
        K.create('textarea[name="content1"]', {
            themeType: 'simple',
            resizeType: 1,
            uploadJson: './resource/kindeditor/php/upload_json.php',
            fileManagerJson: './resource/kindeditor/php/file_manager_json.php',
            allowFileManager: true,
            afterBlur: function(){this.sync();}
        });
        K.create('textarea[name="content2"]', {
            themeType: 'simple',
            resizeType: 1,
            uploadJson: './resource/kindeditor/php/upload_json.php',
            fileManagerJson: './resource/kindeditor/php/file_manager_json.php',
            allowFileManager: true,
            afterBlur: function(){this.sync();}
        });
        K.create('textarea[name="firm_info"]', {
            themeType: 'simple',
            resizeType: 1,
            uploadJson: './resource/kindeditor/php/upload_json.php',
            fileManagerJson: './resource/kindeditor/php/file_manager_json.php',
            allowFileManager: true,
            afterBlur: function(){this.sync();}
        });
    });

    //选择省份
    $("#store_areaId_01").change(function(){
        var _areaID = $(this).val();
        _this = $("#store_areaId_01");
        if(_areaID){
            $.getJSON("./index.php?act=common&op=getAreaChild&parent_id=" + _areaID, function(data){
                $obj = $("#store_areaId_02");
                $obj.empty();
                $obj.append('<option value="">城市</option>');
                $obj.nextAll("select").empty();
                $obj.nextAll("select").append('<option value="">区/县</option>');
                $.each(data, function(i,item){
                    $obj.append('<option value="'+item.area_id+'">'+item.name+'</option>');
                });
            });
        }else{
            _this.nextAll("select").empty();
            _this.next("select").append('<option value="">城市</option>');
            _this.next("select").next('select').append('<option value="">区/县</option>');
        }
    });
    //选择城市
    $("#store_areaId_02").change(function(){
        var _areaID = $(this).val();
        _this = $("#store_areaId_2");
        if(_areaID){
            $.getJSON("index.php?act=common&op=getAreaChild&parent_id=" + _areaID, function(data){
                $obj = $("#store_areaId_03");
                $obj.empty();
                $obj.append('<option value="">区/县</option>');
                $.each(data, function(i,item){
                    $obj.append('<option value="'+item.area_id+'">'+item.name+'</option>');
                });
            });
        }else{
            _this.nextAll("select").empty();
            _this.next("select").append('<option value="">区/县</option>');
        }
    });
    //选择区/县
    $("#store_areaId_03").change(function(){
        var _areaID = $(this).val();
        if(_areaID){
            var area_p = $("#store_areaId_01").find("option:selected").text();
            var area_c = $("#store_areaId_02").find("option:selected").text();
            var area_a = $("#store_areaId_03").find("option:selected").text();
        }
    });
    //选择一级分类
    $("#cate1").change(function(){
        var _tcId = $(this).val();
        _this = $(this);
        if(_tcId){
            $.getJSON("index.php?act=common&op=getCategory&tc_pid=" + _tcId, function(data){
                $obj = $("#cate2");
                $obj.empty();
                $obj.append('<option value="">选择二级分类</option>');
                $.each(data, function(i,item){
                    $obj.append('<option value="'+item.tc_id+'">'+item.tc_name+'</option>');
                });
            });
        }else{
            _this.next("select").empty();
            _this.next("select").append('<option value="">选择二级分类</option>');
        }
    });
    //图片文件选择
    $("#image").change(function(){
        $("#textfield").val($(this).val());
    });
    //图片文件选择
    $("#image1").change(function(){
        $("#textfield1").val($(this).val());
    });
    //图片文件选择
    $("#image2").change(function(){
        $("#textfield2").val($(this).val());
    });
    //活动类型选择
    $("[name='type']").change(function(){
        var valuess = $(this).val();
        if(valuess =='1'){
            $(".add_res").show();
        }else{
            $(".add_res").hide();
        }
    });
    //提交表单
    $("#submitBtn").click(function(){

        if ($("#bargain_form").valid()) {
            if (parseInt($('input[name="type"]:checked').val()) === 0 && $('input[name^="types"]:checked').length === 0) {
                layer.alert('<?php echo $lang['bargain_add_use_null']; ?>', function (index) {
                    $('html,body').animate({scrollTop: $('input[name^="types"]:eq(0)').offset().top - 100}, 300);
                    layer.close(index);
                });
            } else {
                //alert('debug:表单校验ok');
                $("#bargain_form").submit();
            }
        } else {
            $('html,body').animate({scrollTop: $('label.error:visible:eq(0)').offset().top - 70}, 300);
        }
    });
    jQuery.validator.methods.greaterThanStartDate = function(value, element) {
        var start_date = $("#search_stime").val();
        var date1 = new Date(Date.parse(start_date.replace(/-/g, "/")));
        var date2 = new Date(Date.parse(value.replace(/-/g, "/")));
        return date1 < date2;
    };
    jQuery.validator.addMethod("isDigits", function(value, element) {
        return this.optional(element) || /^\d+$/.test(value);
    }, "只能输入0-9数字");
    $("#bargain_form").validate({
        errorPlacement: function(error, element){
            if (element.attr('type') === 'file') {
                error.appendTo(element.parent().parent().parent().prev().find('td:first'));
            } else {
                error.appendTo(element.parent().parent().prev().find('td:first'));
            }
        },
        rules:{
            merchant_id : 'required',
            title: {
                required: true,

            },
            show_price: {
                required: true,
                number: true,
                min: 0.01,
                max: 9999999
            },
            market_price: {
                required: true,
                number: true,
                min: 0.01,
                max: 9999999
            },
            min_price:{
                required: true,
                number: true,
                min: 0.01,
                max: 9999999
            },
            max_price:{
                required: true,
                number: true,
                min: 0.01,
                max: 9999999
            },

            degree:{
                required: true,
                min: 0.1,
                digits:true,
            },
            store:{
                required: true,
                min: 0.1,
                digits:true,
            },
            search_stime : {
                required : true,

            },
            search_etime:{
                required : true,
                greaterThanStartDate:true
            },
            content:'required',
            province_id: {
                required:function(){
                    return $("[name='type']").val() == '1';
                }
            },
            city_id: {
                required:function(){
                    return $("[name='type']").val() == '1';
                }
            },
            area_id: {
                required:function(){
                    return $("[name='type']").val() == '1';
                }
            },
            content2: 'required',
            content1: 'required',
            bg_rs:{
                required: true,
                isDigits:true
            },
            share_sun:{
                required: true,
                isDigits:true
            },
            true_sum:{
                required: true,
                isDigits:true
            }
        },
        messages: {
            merchant_id : '请选择所属商家',
            title : {
                required:'标题不能为空',
            },
            show_price : '价格必须是0.01~9999999之间的数字',
            market_price :'价格必须是0.01~9999999之间的数字',
            content:'商品详情不能为空',
            min_price : '价格必须是0.01~9999999之间的数字',
            max_price : '价格必须是0.01~9999999之间的数字',
            degree:'次数必须为正整数',
            store:'库存必须是大于0的正整数',
            search_stime:{required:'活动开始时间不能为空'},
            search_etime:{
                required:'活动结束时间不能为空',
                greaterThanStartDate:'结束时间必须大于开始时间'
            },
            province_id : '请选择省份',
            city_id: '请选择城市',
            area_id: '请选择地区',
            content2: '公司详细信息不能为空',
            content1: '活动规则不能为空',
            share_sun:{
                required:'分享人数不能为空',
            },
            bg_rs:{
                required:'参与活动人数不能为空',
            },
            true_sum:{
                required:'每日砍价上限不能为空',
            }



        }

    });

</script>
